home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Headers / COMPOBJ.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-30  |  34.2 KB  |  990 lines  |  [TEXT/????]

  1. /*****************************************************************************\
  2. *                                                                             *
  3. * compobj.h -     Component object model definitions                              *
  4. *                                                                             *
  5. *               OLE Version 2.0                                               *
  6. *                                                                             *
  7. *               Copyright (c) 1992-1994, Microsoft Corp. All rights reserved. *
  8. *                                                                             *
  9. \*****************************************************************************/
  10.  
  11.  
  12. #if !defined(__COMPOBJ__) && !defined(_COMPOBJ_H_)
  13. #define __COMPOBJ__
  14. #define _COMPOBJ_H_
  15.  
  16.  
  17. /****** Linkage Definitions *************************************************/
  18.  
  19. /*
  20.  *      These are macros for declaring methods/functions.  They exist so that
  21.  *      control over the use of keywords (CDECL, PASCAL, __export,
  22.  *      extern "C") resides in one place, and because this is the least
  23.  *      intrusive way of writing function declarations that do not have
  24.  *      to be modified in order to port to the Mac.
  25.  *
  26.  *      The macros without the trailing underscore are for functions/methods
  27.  *      which a return value of type HRESULT; this is by far the most common
  28.  *      case in OLE. The macros with a trailing underscore take a return
  29.  *      type as a parameter.
  30.  *
  31.  * WARNING: STDAPI is hard coded into the LPFNGETCLASSOBJECT typedef below.
  32.  */
  33.  
  34. #ifdef __cplusplus
  35.     #define EXTERN_C    extern "C"
  36. #else
  37.     #define EXTERN_C    extern
  38. #endif
  39.  
  40. #if !defined( __MACPUB__ )
  41. #include <macpub.h>
  42. #endif
  43.  
  44.  
  45. #if !defined(_MSC_VER)
  46.   #ifdef __SC__
  47.     #define STDMETHODCALLTYPE        _cdecl
  48.   #else
  49.     #define STDMETHODCALLTYPE
  50.   #endif
  51.     #define STDAPICALLTYPE          pascal
  52.     #define STDAPI                  EXTERN_C STDAPICALLTYPE HRESULT
  53.     #define _STDAPI                 EXTERN_C STDAPICALLTYPE HRESULT
  54.     #define STDAPI_(type)           EXTERN_C STDAPICALLTYPE type
  55.     #define _STDAPI_(type)          EXTERN_C STDAPICALLTYPE type
  56. #else /*  */
  57. #ifndef _PPCMAC
  58.     #define STDMETHODCALLTYPE        __cdecl
  59.     #define STDAPICALLTYPE          __pascal
  60.     #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
  61.     #define _STDAPI                 EXTERN_C HRESULT STDAPICALLTYPE
  62.     #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
  63.     #define _STDAPI_(type)          EXTERN_C type STDAPICALLTYPE
  64. #else
  65.     #define STDMETHODCALLTYPE        
  66.     #define STDAPICALLTYPE          
  67.     #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
  68.     #define _STDAPI                 EXTERN_C HRESULT STDAPICALLTYPE
  69.     #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
  70.     #define _STDAPI_(type)          EXTERN_C type STDAPICALLTYPE
  71. #endif
  72. #endif /*  */
  73.  
  74.  
  75. #define STDMETHODIMP            HRESULT STDMETHODCALLTYPE
  76. #define STDMETHODIMP_(type)     type STDMETHODCALLTYPE
  77.  
  78.  
  79. /****** Interface Declaration ***********************************************/
  80.  
  81. /*
  82.  *      These are macros for declaring interfaces.  They exist so that
  83.  *      a single definition of the interface is simulataneously a proper
  84.  *      declaration of the interface structures (C++ abstract classes)
  85.  *      for both C and C++.
  86.  *
  87.  *      DECLARE_INTERFACE(iface) is used to declare an interface that does
  88.  *      not derive from a base interface.
  89.  *      DECLARE_INTERFACE_(iface, baseiface) is used to declare an interface
  90.  *      that does derive from a base interface.
  91.  *
  92.  *      By default if the source file has a .c extension the C version of
  93.  *      the interface declaratations will be expanded; if it has a .cpp
  94.  *      extension the C++ version will be expanded. if you want to force
  95.  *      the C version expansion even though the source file has a .cpp
  96.  *      extension, then define the macro "CINTERFACE".
  97.  *      eg.     cl -DCINTERFACE file.cpp
  98.  *
  99.  *      Example Interface declaration:
  100.  *
  101.  *          #undef  INTERFACE
  102.  *          #define INTERFACE   IClassFactory
  103.  *
  104.  *          DECLARE_INTERFACE_(IClassFactory, IUnknown)
  105.  *          {
  106.  *              // *** IUnknown methods ***
  107.  *              STDMETHOD(QueryInterface) (THIS_
  108.  *                                        REFIID riid,
  109.  *                                        void * * ppvObj) PURE;
  110.  *              STDMETHOD_(unsigned long,AddRef) (THIS) PURE;
  111.  *              STDMETHOD_(unsigned long,Release) (THIS) PURE;
  112.  *
  113.  *              // *** IClassFactory methods ***
  114.  *              STDMETHOD(CreateInstance) (THIS_
  115.  *                                        LPUNKNOWN pUnkOuter,
  116.  *                                        REFIID riid,
  117.  *                                        void * * ppvObject) PURE;
  118.  *          };
  119.  *
  120.  *      Example C++ expansion:
  121.  *
  122.  *          struct  IClassFactory : public IUnknown
  123.  *          {
  124.  *              virtual HRESULT STDMETHODCALLTYPE QueryInterface(
  125.  *                                                  IID & riid,
  126.  *                                                  void * * ppvObj) = 0;
  127.  *              virtual HRESULT STDMETHODCALLTYPE AddRef(void) = 0;
  128.  *              virtual HRESULT STDMETHODCALLTYPE Release(void) = 0;
  129.  *              virtual HRESULT STDMETHODCALLTYPE CreateInstance(
  130.  *                                              LPUNKNOWN pUnkOuter,
  131.  *                                              IID & riid,
  132.  *                                              void * * ppvObject) = 0;
  133.  *          };
  134.  *
  135.  *          NOTE: Our documentation says '#define interface class' but we use
  136.  *          'struct' instead of 'class' to keep a lot of 'public:' lines
  137.  *          out of the interfaces.  The '' forces the 'this' pointers to
  138.  *          be far, which is what we need.
  139.  *
  140.  *      Example C expansion:
  141.  *
  142.  *          typedef struct IClassFactory
  143.  *          {
  144.  *              const struct IClassFactoryVtbl * lpVtbl;
  145.  *          } IClassFactory;
  146.  *
  147.  *          typedef struct IClassFactoryVtbl IClassFactoryVtbl;
  148.  *
  149.  *          struct IClassFactoryVtbl
  150.  *          {
  151.  *              HRESULT (STDMETHODCALLTYPE * QueryInterface) (
  152.  *                                                  IClassFactory * This,
  153.  *                                                  IID * riid,
  154.  *                                                  void * * ppvObj) ;
  155.  *              HRESULT (STDMETHODCALLTYPE * AddRef) (IClassFactory * This) ;
  156.  *              HRESULT (STDMETHODCALLTYPE * Release) (IClassFactory * This) ;
  157.  *              HRESULT (STDMETHODCALLTYPE * CreateInstance) (
  158.  *                                                  IClassFactory * This,
  159.  *                                                  LPUNKNOWN pUnkOuter,
  160.  *                                                  IID * riid,
  161.  *                                                  void * * ppvObject);
  162.  *              HRESULT (STDMETHODCALLTYPE * LockServer) (
  163.  *                                                  IClassFactory * This,
  164.  *                                                  unsigned long fLock);
  165.  *          };
  166.  */
  167.  
  168.  
  169. #if defined(__cplusplus) && !defined(CINTERFACE)
  170. #ifdef __TURBOC__
  171. #define interface               struct huge
  172. #else
  173. #define interface               struct 
  174. #endif
  175.  
  176. #define STDMETHOD(method)       virtual HRESULT STDMETHODCALLTYPE method
  177. #define STDMETHOD_(type,method) virtual type STDMETHODCALLTYPE method
  178.  
  179. #define PURE                    = 0
  180. #define THIS_
  181. #define THIS                    void
  182. #define DECLARE_INTERFACE(iface)    interface iface
  183. #define DECLARE_INTERFACE_(iface, baseiface)    interface iface : public baseiface
  184.  
  185. #if (defined(_MSC_VER) || defined(__SC__) || defined(__MWERKS__)) && !defined(NO_NULL_VTABLE_ENTRY)
  186. #define BEGIN_INTERFACE
  187. //#define BEGIN_INTERFACE virtual void a() {}
  188. #else
  189. #define BEGIN_INTERFACE
  190. #endif
  191.  
  192. #define END_INTERFACE
  193.  
  194. #else // !__cplusplus
  195.  
  196. #define interface               struct
  197.  
  198.  
  199. #define STDMETHOD(method)       HRESULT (STDMETHODCALLTYPE * method)
  200. #define STDMETHOD_(type,method) type (STDMETHODCALLTYPE * method)
  201.  
  202. #define BEGIN_INTERFACE            void    *b;
  203. #define END_INTERFACE            // void    *b;
  204.  
  205. #define PURE
  206. #define THIS_                   INTERFACE * This,
  207. #define THIS                    INTERFACE * This
  208. #ifdef CONST_VTABLE
  209. #define DECLARE_INTERFACE(iface)    typedef interface iface { \
  210.                                     const struct iface##Vtbl * lpVtbl; \
  211.                                 } iface; \
  212.                                 typedef const struct iface##Vtbl iface##Vtbl; \
  213.                                 const struct iface##Vtbl
  214. #else
  215. #define DECLARE_INTERFACE(iface)    typedef interface iface { \
  216.                                     struct iface##Vtbl * lpVtbl; \
  217.                                 } iface; \
  218.                                 typedef struct iface##Vtbl iface##Vtbl; \
  219.                                 struct iface##Vtbl
  220. #endif
  221. #define DECLARE_INTERFACE_(iface, baseiface)    DECLARE_INTERFACE(iface)
  222.  
  223. #endif
  224.  
  225.  
  226. /****** Additional basic types **********************************************/
  227.  
  228.  
  229. #ifndef FARSTRUCT
  230. #ifdef __cplusplus
  231. #define FARSTRUCT   
  232. #else
  233. #define FARSTRUCT   
  234. #endif  // __cplusplus
  235. #endif  // FARSTRUCT
  236.  
  237.  
  238.  
  239. #ifndef WIN32
  240. #ifndef _WINNT_ 
  241. typedef struct FARSTRUCT _LARGE_INTEGER {
  242.     unsigned long LowPart;
  243.     long  HighPart;
  244. } LARGE_INTEGER, *PLARGE_INTEGER;
  245. #endif
  246. #endif
  247. #define LISet32(li, v) ((li).HighPart = ((long)(v)) < 0 ? -1 : 0, (li).LowPart = (v))
  248.  
  249. #ifndef WIN32
  250. #ifndef _WINNT_ 
  251. typedef struct FARSTRUCT _ULARGE_INTEGER {
  252.     unsigned long LowPart;
  253.     unsigned long HighPart;
  254. } ULARGE_INTEGER, *PULARGE_INTEGER;
  255. #endif
  256. #endif
  257. #define ULISet32(li, v) ((li).HighPart = 0, (li).LowPart = (v))
  258.  
  259. #ifndef _WINDOWS_
  260. #ifndef _FILETIME_
  261. #define _FILETIME_
  262. typedef struct FARSTRUCT tagFILETIME
  263. {
  264.     unsigned long dwLowDateTime;
  265.     unsigned long dwHighDateTime;
  266. } FILETIME;
  267. #endif
  268. #endif
  269.  
  270. #ifndef __SCODE__
  271. #include "scode.h"
  272. #endif
  273.  
  274.  
  275. // *********************** Compobj errors **********************************
  276.  
  277. #define CO_E_NOTINITIALIZED         (CO_E_FIRST + 0x0)
  278. // CoInitialize has not been called and must be
  279.  
  280. #define CO_E_ALREADYINITIALIZED     (CO_E_FIRST + 0x1)
  281. // CoInitialize has already been called and cannot be called again (temporary)
  282.  
  283. #define CO_E_CANTDETERMINECLASS     (CO_E_FIRST + 0x2)
  284. // can't determine clsid (e.g., extension not in reg.dat)
  285.  
  286. #define CO_E_CLASSSTRING            (CO_E_FIRST + 0x3)
  287. // the string form of the clsid is invalid (including ole1 classes)
  288.  
  289. #define CO_E_IIDSTRING              (CO_E_FIRST + 0x4)
  290. // the string form of the iid is invalid
  291.  
  292. #define CO_E_APPNOTFOUND            (CO_E_FIRST + 0x5)
  293. // application not found
  294.  
  295. #define CO_E_APPSINGLEUSE           (CO_E_FIRST + 0x6)
  296. // application cannot be run more than once
  297.  
  298. #define CO_E_ERRORINAPP             (CO_E_FIRST + 0x7)
  299. // some error in the app program file
  300.  
  301. #define CO_E_DLLNOTFOUND            (CO_E_FIRST + 0x8)
  302. // dll not found
  303.  
  304. #define CO_E_ERRORINDLL             (CO_E_FIRST + 0x9)
  305. // some error in the dll file
  306.  
  307. #define CO_E_WRONGOSFORAPP          (CO_E_FIRST + 0xa)
  308. // app written for other version of OS or other OS altogether
  309.  
  310. #define CO_E_OBJNOTREG              (CO_E_FIRST + 0xb)
  311. // object is not registered
  312.  
  313. #define CO_E_OBJISREG               (CO_E_FIRST + 0xc)
  314. // object is already registered
  315.  
  316. #define CO_E_OBJNOTCONNECTED        (CO_E_FIRST + 0xd)
  317. // handler is not connected to server
  318.  
  319. #define CO_E_APPDIDNTREG            (CO_E_FIRST + 0xe)
  320. // app was launched, but didn't registered a class factory
  321.  
  322.  
  323. // ********************* ClassObject errors ********************************
  324.  
  325. #define CLASS_E_NOAGGREGATION       (CLASSFACTORY_E_FIRST + 0x0)
  326. // class does not support aggregation (or class object is remote)
  327.  
  328. #define CLASS_E_CLASSNOTAVAILABLE   (CLASSFACTORY_E_FIRST + 0x1)
  329. // dll doesn't support that class (returned from DllGetClassObject)
  330.  
  331.  
  332. // *********************** Reg.dat errors **********************************
  333.  
  334. #define REGDB_E_READREGDB           (REGDB_E_FIRST + 0x0)
  335. // some error reading the registration database
  336.  
  337. #define REGDB_E_WRITEREGDB          (REGDB_E_FIRST + 0x1)
  338. // some error reading the registration database
  339.  
  340. #define REGDB_E_KEYMISSING          (REGDB_E_FIRST + 0x2)
  341. // some error reading the registration database
  342.  
  343. #define REGDB_E_INVALIDVALUE        (REGDB_E_FIRST + 0x3)
  344. // some error reading the registration database
  345.  
  346. #define REGDB_E_CLASSNOTREG         (REGDB_E_FIRST + 0x4)
  347. // some error reading the registration database
  348.  
  349. #define REGDB_E_IIDNOTREG           (REGDB_E_FIRST + 0x5)
  350. // some error reading the registration database
  351.  
  352.  
  353. // *************************** RPC errors **********************************
  354.  
  355. #define RPC_E_FIRST    MAKE_SCODE(SEVERITY_ERROR, FACILITY_RPC,  0x000)
  356.  
  357. // call was rejected by callee, either by MF::HandleIncomingCall or
  358. #define RPC_E_CALL_REJECTED             (RPC_E_FIRST + 0x1)         
  359.  
  360. // call was canceld by call - returned by MessagePending
  361. // this code only occurs if MessagePending return cancel
  362. #define RPC_E_CALL_CANCELED             (RPC_E_FIRST + 0x2)         
  363.  
  364. // the caller is dispatching an intertask SendMessage call and 
  365. // can NOT call out via PostMessage
  366. #define RPC_E_CANTPOST_INSENDCALL       (RPC_E_FIRST + 0x3)             
  367.  
  368. // the caller is dispatching an asynchronus call can NOT 
  369. // make an outgoing call on behalf of this call
  370. #define RPC_E_CANTCALLOUT_INASYNCCALL   (RPC_E_FIRST + 0x4)         
  371.  
  372. // the caller is not in a state where an outgoing call can be made
  373. // this is the case if the caller has an outstandig call and
  374. // another incoming call was excepted by HIC; now the caller is
  375. // not allowed to call out again
  376. #define RPC_E_CANTCALLOUT_INEXTERNALCALL (RPC_E_FIRST + 0x5)                
  377.  
  378. // the connection terminated or is in a bogus state
  379. // and can not be used any more. Other connections
  380. // are still valid.
  381. #define RPC_E_CONNECTION_TERMINATED     (RPC_E_FIRST + 0x6)         
  382.  
  383. // the callee (server [not server application]) is not available 
  384. // and disappeared; all connections are invalid
  385. #define RPC_E_SERVER_DIED               (RPC_E_FIRST + 0x7)         
  386.  
  387. // the caller (client ) disappeared while the callee (server) was 
  388. // processing a call 
  389. #define RPC_E_CLIENT_DIED               (RPC_E_FIRST + 0x8)         
  390.  
  391. // the date paket with the marshalled parameter data is
  392. // incorrect 
  393. #define RPC_E_INVALID_DATAPACKET        (RPC_E_FIRST + 0x9)         
  394.  
  395. // the call was not transmitted properly; the message queue 
  396. // was full and was not emptied after yielding
  397. #define RPC_E_CANTTRANSMIT_CALL         (RPC_E_FIRST + 0xa)         
  398.  
  399. // the client (caller) can not marshall the parameter data 
  400. // or unmarshall the return data - low memory etc.
  401. #define RPC_E_CLIENT_CANTMARSHAL_DATA   (RPC_E_FIRST + 0xb)         
  402. #define RPC_E_CLIENT_CANTUNMARSHAL_DATA (RPC_E_FIRST + 0xc)         
  403.  
  404. // the server (caller) can not unmarshall the parameter data
  405. // or marshall the return data - low memory
  406. #define RPC_E_SERVER_CANTMARSHAL_DATA   (RPC_E_FIRST + 0xd)         
  407. #define RPC_E_SERVER_CANTUNMARSHAL_DATA (RPC_E_FIRST + 0xe)         
  408.  
  409. // received data are invalid; can be server or 
  410. // client data
  411. #define RPC_E_INVALID_DATA              (RPC_E_FIRST + 0xf)         
  412.  
  413. // a particular parameter is invalid and can not be un/marshalled
  414. #define RPC_E_INVALID_PARAMETER         (RPC_E_FIRST + 0x10)
  415.  
  416. // DDE conversation - no second outgoing call on same channel
  417. #define RPC_E_CANTCALLOUT_AGAIN            (RPC_E_FIRST + 0x11)         
  418.  
  419. // a internal error occured 
  420. #define RPC_E_UNEXPECTED                (RPC_E_FIRST + 0xFFFF)
  421.  
  422.  
  423. /****** Globally Unique Ids *************************************************/
  424.  
  425. #ifdef __cplusplus
  426.  
  427. struct  GUID
  428. {
  429.     unsigned long Data1;
  430.     unsigned short  Data2;
  431.     unsigned short  Data3;
  432.     unsigned char  Data4[8];
  433.  
  434.     unsigned long operator==(const GUID& iidOther) const
  435.  
  436.         {    return ((Data1 == iidOther.Data1) &&
  437.                     (Data2 == iidOther.Data2) &&
  438.                     (Data3 == iidOther.Data3) &&
  439.                     (* (long*) Data4 == *(long*)iidOther.Data4) &&
  440.                     (* (long*) (Data4+4) == *( (long*) (iidOther.Data4+4)) ) );
  441.         }
  442.     unsigned long operator!=(const GUID& iidOther) const
  443.         { return !((*this) == iidOther); }
  444. };
  445.  
  446. #else
  447. typedef struct GUID
  448. {
  449.     unsigned long Data1;
  450.     unsigned short  Data2;
  451.     unsigned short  Data3;
  452.     unsigned char  Data4[8];
  453. } GUID;
  454. #endif
  455.  
  456. typedef                GUID * LPGUID;
  457.  
  458.  
  459. // macros to define byte pattern for a GUID.  
  460. //      Example: DEFINE_GUID(GUID_XXX, a, b, c, ...);
  461. //
  462. // Each dll/exe must initialize the GUIDs once.  This is done in one of
  463. // two ways.  If you are not using precompiled headers for the file(s) which
  464. // initializes the GUIDs, define INITGUID before including compobj.h.  This
  465. // is how OLE builds the initialized versions of the GUIDs which are included
  466. // in compobj.dll.
  467. //
  468. // The alternative (which some versions of the compiler don't handle properly;
  469. // they wind up with the initialized GUIDs in a data, not a text segment),
  470. // is to use a precompiled version of compobj.h and then include initguid.h 
  471. // after compobj.h followed by one or more of the guid defintion files.
  472.  
  473.  
  474. #if !defined(_MSC_VER) || defined(_PPCMAC)
  475. #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  476.     EXTERN_C const GUID name
  477. #else
  478. #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  479.     EXTERN_C __declspec(allocate("_FAR_DATA")) GUID name
  480. #endif
  481.  
  482. #ifdef INITGUID
  483. #include "initguid.h"
  484. #endif
  485.  
  486.  
  487. #define DEFINE_OLEGUID(name, l, w1, w2) \
  488.     DEFINE_GUID(name, l, w1, w2, 0xC0,0,0,0,0,0,0,0x46)
  489.  
  490.  
  491. // Interface ID are just a kind of GUID
  492. typedef GUID IID;
  493. typedef                IID * LPIID;
  494. #define IID_NULL            GUID_NULL
  495. #define IsEqualIID(riid1, riid2) IsEqualGUID(riid1, riid2)
  496.  
  497.  
  498. // Class ID are just a kind of GUID
  499. typedef GUID CLSID;
  500. typedef              CLSID * LPCLSID;
  501. #define CLSID_NULL          GUID_NULL
  502. #define IsEqualCLSID(rclsid1, rclsid2) IsEqualGUID(rclsid1, rclsid2)
  503.  
  504.  
  505. #if defined(__cplusplus)
  506. #define REFGUID             const GUID &
  507. #define REFIID              const IID &
  508. #define REFCLSID            const CLSID &
  509. #else
  510. #define REFGUID             const GUID * const
  511. #define REFIID              const IID * const
  512. #define REFCLSID            const CLSID * const
  513. #endif
  514.  
  515.  
  516. #ifndef INITGUID
  517. #include "coguid.h"
  518. #endif
  519.  
  520.  
  521. /****** Other value types ***************************************************/
  522.  
  523. // memory context values; passed to CoGetMalloc
  524. typedef enum tagMEMCTX
  525. {
  526.     MEMCTX_TASK = 1,            // task (private) memory
  527.     MEMCTX_SHARED = 2,           // shared memory (between processes)
  528.  
  529.     // these are mostly for internal use...
  530.     MEMCTX_UNKNOWN = -1,        // unknown context (when asked about it)
  531.     MEMCTX_SAME = -2           // same context (as some other pointer)
  532.     ,MEMCTX_FORCELONG    =    2147483647
  533. } MEMCTX;
  534.  
  535.  
  536.  
  537. // class context: used to determine what scope and kind of class object to use
  538. // NOTE: this is a bitwise enum
  539. typedef enum tagCLSCTX
  540. {
  541.     CLSCTX_INPROC_SERVER = 1,   // server dll (runs in same process as caller)
  542.     CLSCTX_INPROC_HANDLER = 2,  // handler dll (runs in same process as caller)
  543.     CLSCTX_LOCAL_SERVER = 4     // server exe (runs on same machine; diff proc)
  544.     ,CLSCTX_FORCELONG    =    2147483647
  545. } CLSCTX;
  546.  
  547. #define CLSCTX_ALL              (CLSCTX_INPROC_SERVER| \
  548.                                  CLSCTX_INPROC_HANDLER| \
  549.                                  CLSCTX_LOCAL_SERVER)
  550.  
  551. #define CLSCTX_INPROC           (CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER)
  552.  
  553. #define CLSCTX_SERVER           (CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER)
  554.  
  555.  
  556. // class registration flags; passed to CoRegisterClassObject
  557. typedef enum tagREGCLS
  558. {
  559.     REGCLS_SINGLEUSE = 0,       // class object only generates one instance
  560.     REGCLS_MULTIPLEUSE = 1,     // same class object genereates multiple inst.
  561.                                 // and local automatically goes into inproc tbl.
  562.     REGCLS_MULTI_SEPARATE = 2   // multiple use, but separate control over each
  563.                                 // context.
  564.  
  565.     // NOTE: CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE is the same as
  566.     // (CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER), REGCLS_MULTI_SEPARATE, but
  567.     // not the same as CLSCTX_LOCAL_SERVER, REGCLS_MULTI_SEPARATE.
  568.     ,REGCLS_FORCELONG    =    2147483647
  569. } REGCLS;
  570.  
  571.  
  572. // interface marshaling definitions
  573. #define MARSHALINTERFACE_MIN 40 // minimum number of bytes for interface marshl
  574.  
  575. // marshaling flags; passed to CoMarshalInterface
  576. typedef enum tagMSHLFLAGS
  577. {
  578.     MSHLFLAGS_NORMAL = 0,       // normal marshaling via proxy/stub
  579.     MSHLFLAGS_TABLESTRONG = 1,  // keep object alive; must explicitly release
  580.     MSHLFLAGS_TABLEWEAK = 2     // doesn't hold object alive; still must release
  581.     ,MSHLFLAGS_FORCELONG    =    2147483647
  582. } MSHLFLAGS;
  583.  
  584. // marshal context: determines the destination context of the marshal operation
  585. typedef enum tagMSHCTX
  586. {
  587.     MSHCTX_LOCAL = 0,             // unmarshal context is local (eg.shared memory)
  588.     MSHCTX_NOSHAREDMEM = 1     // unmarshal context has no shared memory access
  589.     ,MSHCTX_FORCELONG    =    2147483647
  590. } MSHCTX;
  591.  
  592.  
  593. // call type used by IMessageFilter::HandleIncommingMessage
  594. typedef enum tagCALLTYPE
  595. {
  596.     CALLTYPE_TOPLEVEL = 1,      // toplevel call - no outgoing call 
  597.     CALLTYPE_NESTED   = 2,      // callback on behalf of previous outgoing call - should always handle
  598.     CALLTYPE_ASYNC    = 3,        // aysnchronous call - can NOT be rejected
  599.     CALLTYPE_TOPLEVEL_CALLPENDING = 4,  // new toplevel call with new LID
  600.     CALLTYPE_ASYNC_CALLPENDING    = 5   // async call - can NOT be rejected
  601.     ,CALLTYPE_FORCELONG    =    2147483647
  602. } CALLTYPE;
  603.  
  604.  
  605. typedef struct tagINTERFACEINFO 
  606. {               
  607.     interface IUnknown *pUnk;       // the pointer to the object
  608.     IID                  iid;            // interface id
  609.     short                wMethod;        // interface methode
  610. } INTERFACEINFO, * LPINTERFACEINFO;
  611.  
  612. // status of server call - returned by IMessageFilter::HandleIncommingCall
  613. // and passed to  IMessageFilter::RetryRejectedCall
  614. typedef enum tagSERVERCALL
  615. {
  616.     SERVERCALL_ISHANDLED    = 0,
  617.     SERVERCALL_REJECTED     = 1,
  618.     SERVERCALL_RETRYLATER   = 2         
  619.     ,SERVERCALL_FORCELONG    =    2147483647
  620. } SERVERCALL;
  621.  
  622. // Pending type indicates the level of nesting
  623. typedef enum tagPENDINGTYPE
  624. {   
  625.     PENDINGTYPE_TOPLEVEL = 1, // toplevel call
  626.     PENDINGTYPE_NESTED   = 2  // nested call
  627.     ,PENDINGTYPEE_FORCELONG    =    2147483647
  628. } PENDINGTYPE;
  629.  
  630. // return values of MessagePending
  631. typedef enum tagPENDINGMSG
  632. {   
  633.     PENDINGMSG_CANCELCALL  = 0, // cancel the outgoing call
  634.     PENDINGMSG_WAITNOPROCESS  = 1, // wait for the return and don't dispatch the message
  635.     PENDINGMSG_WAITDEFPROCESS = 2  // wait and dispatch the message     
  636.     ,PENDINGMSG_FORCELONG    =    2147483647
  637. } PENDINGMSG;
  638.  
  639. // bit flags for IExternalConnection
  640. typedef enum tagEXTCONN 
  641. {
  642.     EXTCONN_STRONG        = 0x0001    // strong connection
  643.     ,EXTCONN_FORCELONG    =    2147483647
  644. } EXTCONN;
  645.  
  646.  
  647.  
  648. /****** IUnknown Interface **************************************************/
  649.  
  650.  
  651. #undef  INTERFACE
  652. #define INTERFACE   IUnknown
  653.  
  654. #if ( !defined(applec) || defined(__SC__) || defined(_MSC_VER) ) && !defined(__MWERKS__)
  655. DECLARE_INTERFACE(IUnknown)
  656. #else
  657. // MPW declaration to force SI vtable construction.
  658.  
  659. // jjo For testing with CW9 with __comobject compiler path from Andreas Hommel 
  660. //DECLARE_INTERFACE_(IUnknown, SingleObject)
  661. DECLARE_INTERFACE_(IUnknown, __comobject)
  662.  
  663. #endif
  664. {
  665.     BEGIN_INTERFACE
  666.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, void * * ppvObj) PURE;
  667.     STDMETHOD_(unsigned long,AddRef) (THIS)  PURE;
  668.     STDMETHOD_(unsigned long,Release) (THIS) PURE;
  669. };
  670. typedef        IUnknown * LPUNKNOWN, ** LPLPUNKNOWN;
  671.  
  672.  
  673. /****** Class Factory Interface *******************************************/
  674.  
  675.  
  676. #undef  INTERFACE
  677. #define INTERFACE   IClassFactory
  678.  
  679. DECLARE_INTERFACE_(IClassFactory, IUnknown)
  680. {
  681.     BEGIN_INTERFACE
  682.     // *** IUnknown methods ***
  683.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, void * * ppvObj) PURE;
  684.     STDMETHOD_(unsigned long,AddRef) (THIS)  PURE;
  685.     STDMETHOD_(unsigned long,Release) (THIS) PURE;
  686.  
  687.     // *** IClassFactory methods ***
  688.     STDMETHOD(CreateInstance) (THIS_ LPUNKNOWN pUnkOuter,
  689.                               REFIID riid,
  690.                               void * * ppvObject) PURE;
  691.     STDMETHOD(LockServer) (THIS_ unsigned long fLock) PURE;
  692.  
  693. };
  694. typedef       IClassFactory * LPCLASSFACTORY, ** LPLPCLASSFACTORY;
  695.  
  696.  
  697. /****** Memory Allocation Interface ***************************************/
  698.  
  699.  
  700. #undef  INTERFACE
  701. #define INTERFACE   IMalloc
  702.  
  703. DECLARE_INTERFACE_(IMalloc, IUnknown)
  704. {
  705.     BEGIN_INTERFACE
  706.     // *** IUnknown methods ***
  707.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, void * * ppvObj) PURE;
  708.     STDMETHOD_(unsigned long,AddRef) (THIS)  PURE;
  709.     STDMETHOD_(unsigned long,Release) (THIS) PURE;
  710.  
  711.     // *** IMalloc methods ***
  712.     STDMETHOD_(void *, Alloc) (THIS_ unsigned long cb) PURE;
  713.     STDMETHOD_(void *, Realloc) (THIS_ void * pv, unsigned long cb) PURE;
  714.     STDMETHOD_(void, Free) (THIS_ void * pv) PURE;
  715.     STDMETHOD_(unsigned long, GetSize) (THIS_ void * pv) PURE;
  716.     STDMETHOD_(int, DidAlloc) (THIS_ void * pv) PURE;
  717.     STDMETHOD_(void, HeapMinimize) (THIS) PURE;
  718. };
  719. typedef       IMalloc * LPMALLOC, ** LPLPMALLOC;
  720.  
  721.  
  722. /****** IMarshal Interface ************************************************/
  723.  
  724. // forward declaration for IStream; must include storage.h later to use
  725. #ifdef __cplusplus
  726. interface IStream;
  727. #endif
  728. typedef  interface IStream * LPSTREAM, ** LPLPSTREAM;
  729.  
  730.  
  731. #undef  INTERFACE
  732. #define INTERFACE   IMarshal
  733.  
  734. DECLARE_INTERFACE_(IMarshal, IUnknown)
  735. {
  736.     BEGIN_INTERFACE
  737.     // *** IUnknown methods ***
  738.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, void * * ppvObj) PURE;
  739.     STDMETHOD_(unsigned long,AddRef) (THIS)  PURE;
  740.     STDMETHOD_(unsigned long,Release) (THIS) PURE;
  741.  
  742.     // *** IMarshal methods ***
  743.     STDMETHOD(GetUnmarshalClass)(THIS_ REFIID riid, void * pv, 
  744.                         unsigned long dwDestContext, void * pvDestContext,
  745.                         unsigned long mshlflags, LPCLSID pCid) PURE;
  746.     STDMETHOD(GetMarshalSizeMax)(THIS_ REFIID riid, void * pv, 
  747.                         unsigned long dwDestContext, void * pvDestContext,
  748.                         unsigned long mshlflags, unsigned long    * pSize) PURE;
  749.     STDMETHOD(MarshalInterface)(THIS_ LPSTREAM pStm, REFIID riid,
  750.                         void * pv, unsigned long dwDestContext, void * pvDestContext,
  751.                         unsigned long mshlflags) PURE;
  752.     STDMETHOD(UnmarshalInterface)(THIS_ LPSTREAM pStm, REFIID riid,
  753.                         void * * ppv) PURE;
  754.     STDMETHOD(ReleaseMarshalData)(THIS_ LPSTREAM pStm) PURE;
  755.     STDMETHOD(DisconnectObject)(THIS_ unsigned long dwReserved) PURE;
  756. };
  757. typedef         IMarshal * LPMARSHAL, ** LPLPMARSHAL;
  758.  
  759.  
  760. #undef  INTERFACE
  761. #define INTERFACE   IStdMarshalInfo
  762.  
  763. DECLARE_INTERFACE_(IStdMarshalInfo, IUnknown)
  764. {
  765.     BEGIN_INTERFACE
  766.     // *** IUnknown methods ***
  767.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, void * * ppvObj) PURE;
  768.     STDMETHOD_(unsigned long,AddRef) (THIS)  PURE;
  769.     STDMETHOD_(unsigned long,Release) (THIS) PURE;
  770.  
  771.     // *** IStdMarshalInfo methods ***
  772.     STDMETHOD(GetClassForHandler)(THIS_ unsigned long dwDestContext, 
  773.                         void * pvDestContext, LPCLSID pClsid) PURE;
  774. };
  775. typedef         IStdMarshalInfo * LPSTDMARSHALINFO, ** LPLPSTDMARSHALINFO;
  776.  
  777.  
  778. /****** Message Filter Interface *******************************************/
  779.  
  780.  
  781. #undef  INTERFACE
  782. #define INTERFACE   IMessageFilter
  783.  
  784. DECLARE_INTERFACE_(IMessageFilter, IUnknown)
  785. {
  786.     BEGIN_INTERFACE
  787.     // *** IUnknown methods ***
  788.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, void * * ppvObj) PURE;
  789.     STDMETHOD_(unsigned long,AddRef) (THIS)  PURE;
  790.     STDMETHOD_(unsigned long,Release) (THIS) PURE;
  791.  
  792.     // *** IMessageFilter methods ***
  793.     STDMETHOD_(unsigned long, HandleInComingCall) (THIS_ unsigned long dwCallType,
  794.                                 ProcessSerialNumber *pPSNCaller, unsigned long dwTickCount,
  795.                                 LPINTERFACEINFO lpInterfaceInfo ) PURE;
  796.     STDMETHOD_(unsigned long, RetryRejectedCall) (THIS_ 
  797.                                 ProcessSerialNumber *pPSNCallee, unsigned long dwTickCount,
  798.                                 unsigned long dwRejectType ) PURE;
  799.     STDMETHOD_(unsigned long, MessagePending) (THIS_ 
  800.                                 ProcessSerialNumber *pPSNCallee, unsigned long dwTickCount, 
  801.                                 unsigned long dwPendingType  ) PURE; 
  802. };
  803. typedef       IMessageFilter * LPMESSAGEFILTER, ** LPLPMESSAGEFILTER;
  804.  
  805.  
  806. /****** External Connection Information ***********************************/
  807.  
  808. #undef  INTERFACE
  809. #define INTERFACE   IExternalConnection
  810.  
  811. DECLARE_INTERFACE_(IExternalConnection, IUnknown)
  812. {
  813.     BEGIN_INTERFACE
  814.     // *** IUnknown methods ***
  815.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, void * * ppvObj) PURE;
  816.     STDMETHOD_(unsigned long,AddRef) (THIS)  PURE;
  817.     STDMETHOD_(unsigned long,Release) (THIS) PURE;
  818.  
  819.     // *** IExternalConnection methods ***
  820.     STDMETHOD_(unsigned long, AddConnection) (THIS_ unsigned long extconn, unsigned long reserved) PURE;
  821.     STDMETHOD_(unsigned long, ReleaseConnection) (THIS_ unsigned long extconn, unsigned long reserved, unsigned long fLastReleaseCloses) PURE;
  822. };
  823. typedef       IExternalConnection * LPEXTERNALCONNECTION, ** LPLPEXTERNALCONNECTION;
  824.  
  825.  
  826. /****** Enumerator Interfaces *********************************************/
  827.  
  828. /*
  829.  *  Since we don't use parametrized types, we put in explicit declarations
  830.  *  of the enumerators we need.
  831.  */
  832.  
  833.  
  834. #undef  INTERFACE
  835. #define INTERFACE   IEnumString
  836.  
  837. DECLARE_INTERFACE_(IEnumString, IUnknown)
  838. {
  839.     BEGIN_INTERFACE
  840.     // *** IUnknown methods ***
  841.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, void * * ppvObj) PURE;
  842.     STDMETHOD_(unsigned long,AddRef) (THIS)  PURE;
  843.     STDMETHOD_(unsigned long,Release) (THIS) PURE;
  844.  
  845.     // *** IEnumString methods ***
  846.     STDMETHOD(Next) (THIS_ unsigned long celt, 
  847.                        char * * rgelt, 
  848.                        unsigned long * pceltFetched) PURE;
  849.     STDMETHOD(Skip) (THIS_ unsigned long celt) PURE;
  850.     STDMETHOD(Reset) (THIS) PURE;
  851.     STDMETHOD(Clone) (THIS_ IEnumString * * ppenm) PURE;
  852. };
  853. typedef      IEnumString * LPENUMSTRING, ** LPLPENUMSTRING;
  854.  
  855.  
  856. #undef  INTERFACE
  857. #define INTERFACE   IEnumUnknown
  858.  
  859. DECLARE_INTERFACE_(IEnumUnknown, IUnknown)
  860. {
  861.     BEGIN_INTERFACE
  862.     // *** IUnknown methods ***
  863.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, void * * ppvObj) PURE;
  864.     STDMETHOD_(unsigned long,AddRef) (THIS)  PURE;
  865.     STDMETHOD_(unsigned long,Release) (THIS) PURE;
  866.  
  867.     // *** IEnumUnknown methods ***
  868.     STDMETHOD(Next) (THIS_ unsigned long celt, LPLPUNKNOWN rgelt, unsigned long * pceltFetched) PURE;
  869.     STDMETHOD(Skip) (THIS_ unsigned long celt) PURE;
  870.     STDMETHOD(Reset) (THIS) PURE;
  871.     STDMETHOD(Clone) (THIS_ IEnumUnknown * * ppenm) PURE;
  872. };
  873. typedef         IEnumUnknown * LPENUMUNKNOWN, ** LPLPENUMUNKNOWN;
  874.  
  875.  
  876. /****** STD Object API Prototypes *****************************************/
  877.  
  878. STDAPI_(unsigned long) CoBuildVersion( void );
  879.  
  880. /* init/uninit */
  881.  
  882. STDAPI  CoInitialize(LPMALLOC pMalloc);
  883. STDAPI_(void)  CoUninitialize(void);
  884. STDAPI  CoGetMalloc(unsigned long dwMemContext, LPLPMALLOC ppMalloc);
  885. STDAPI_(unsigned long) CoGetCurrentProcess(void);
  886. STDAPI  CoCreateStandardMalloc(unsigned long memctx, IMalloc **ppMalloc);
  887.  
  888.  
  889. /* register/revoke/get class objects */
  890.  
  891. STDAPI  CoGetClassObject(REFCLSID rclsid, unsigned long dwClsContext, void * pvReserved,
  892.                     REFIID riid, void * * ppv);
  893. STDAPI  CoRegisterClassObject(REFCLSID rclsid, LPUNKNOWN pUnk,
  894.                     unsigned long dwClsContext, unsigned long flags, unsigned long    * lpdwRegister);
  895. STDAPI  CoRevokeClassObject(unsigned long dwRegister);
  896.  
  897.  
  898. /* marshaling interface pointers */
  899.  
  900. STDAPI CoMarshalInterface(LPSTREAM pStm, REFIID riid, LPUNKNOWN pUnk,
  901.                     unsigned long dwDestContext, void * pvDestContext, unsigned long mshlflags);
  902. STDAPI CoUnmarshalInterface(LPSTREAM pStm, REFIID riid, void * * ppv);
  903. STDAPI CoMarshalHresult(LPSTREAM pstm, HRESULT hresult);
  904. STDAPI CoUnmarshalHresult(LPSTREAM pstm, HRESULT  * phresult);
  905. STDAPI CoReleaseMarshalData(LPSTREAM pStm);
  906. STDAPI CoDisconnectObject(LPUNKNOWN pUnk, unsigned long dwReserved);
  907. STDAPI CoLockObjectExternal(LPUNKNOWN pUnk, unsigned long fLock, unsigned long fLastUnlockReleases);
  908. STDAPI CoGetStandardMarshal(REFIID riid, LPUNKNOWN pUnk, 
  909.                     unsigned long dwDestContext, void * pvDestContext, unsigned long mshlflags,
  910.                     LPLPMARSHAL ppMarshal);
  911.  
  912. STDAPI_(unsigned long) CoIsHandlerConnected(LPUNKNOWN pUnk);
  913.  
  914. /* dll loading helpers; keeps track of ref counts and unloads all on exit */
  915.  
  916. STDAPI_(long) CoLoadLibrary(char * lpszLibName, unsigned long bAutoFree);
  917. STDAPI_(void) CoFreeLibrary(long hInst);
  918. STDAPI_(void) CoFreeAllLibraries(void);
  919. STDAPI_(void) CoFreeUnusedLibraries(void);
  920.  
  921.  
  922. /* helper for creating instances */
  923.  
  924. STDAPI CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter,
  925.                     unsigned long dwClsContext, REFIID riid, void * * ppv);
  926.  
  927.  
  928. /* other helpers */
  929.  
  930. STDAPI_(unsigned long) IsEqualGUID(REFGUID rguid1, REFGUID rguid2);
  931. STDAPI StringFromCLSID(REFCLSID rclsid, char * * lplpsz);
  932. STDAPI CLSIDFromString(char * lpsz, LPCLSID pclsid);
  933. STDAPI StringFromIID(REFIID rclsid, char * * lplpsz);
  934. STDAPI IIDFromString(char * lpsz, LPIID lpiid);
  935. STDAPI_(unsigned long) CoIsOle1Class(REFCLSID rclsid);
  936. STDAPI ProgIDFromCLSID (REFCLSID clsid, char * * lplpszProgID);
  937. STDAPI CLSIDFromProgID (const char * lpszProgID, LPCLSID lpclsid);
  938.  
  939. STDAPI_(int) StringFromGUID2(REFGUID rguid, char *lpsz, int cbMax);
  940.  
  941. STDAPI CoCreateGuid(GUID *pguid);
  942.  
  943.  
  944. STDAPI_(unsigned long) CoFileTimeToMacDateTime(FILETIME * lpFileTime, unsigned long *psecs);
  945. STDAPI_(unsigned long) CoMacDateTimeToFileTime(unsigned long secs, FILETIME * lpFileTime);
  946.  
  947. STDAPI CoFileTimeNow( FILETIME * lpFileTime );
  948.  
  949. STDAPI CoRegisterMessageFilter( LPMESSAGEFILTER lpMessageFilter,
  950.                                 LPLPMESSAGEFILTER lplpMessageFilter );
  951.  
  952.  
  953. /* TreatAs APIS */
  954.  
  955. STDAPI CoGetTreatAsClass(REFCLSID clsidOld, LPCLSID pClsidNew);
  956. STDAPI CoTreatAsClass(REFCLSID clsidOld, REFCLSID clsidNew);
  957.  
  958.  
  959. /* the server dlls must define their DllGetClassObject and DllCanUnloadNow
  960.  * to match these; the typedefs are located here to ensure all are changed at 
  961.  * the same time.
  962.  */
  963.  
  964. STDAPI  DllGetClassObject(REFCLSID rclsid, REFIID riid, void * * ppv);
  965. STDAPI  DllCanUnloadNow(void);
  966.  
  967. #if !defined(_MSC_VER)
  968. typedef STDAPICALLTYPE HRESULT (* LPFNGETCLASSOBJECT) (REFCLSID, REFIID, void * *);
  969. typedef STDAPICALLTYPE HRESULT (* LPFNCANUNLOADNOW)(void);
  970. #else
  971. typedef HRESULT (STDAPICALLTYPE * LPFNGETCLASSOBJECT) (REFCLSID, REFIID, void * *);
  972. typedef HRESULT (STDAPICALLTYPE * LPFNCANUNLOADNOW)(void);
  973. #endif
  974.  
  975.  
  976. /****** Default Memory Allocation ******************************************/
  977. STDAPI_(void *) CoTaskMemAlloc(unsigned long cb);
  978. STDAPI_(void *) CoTaskMemRealloc(void *pv, unsigned long cb);
  979. STDAPI_(void)   CoTaskMemFree(void *pv);
  980.  
  981.  
  982. /****** Debugging Helpers *************************************************/
  983.  
  984. #ifdef _DEBUG
  985. // writes to the debug port and displays a message box
  986. STDAPI FnAssert(char * lpstrExpr, char * lpstrMsg, char * lpstrFileName, unsigned short iLine);
  987. #endif /* _DEBUG */
  988.  
  989. #endif /* !__COMPOBJ__ */
  990.